/*
 * Copyright 2007 National Bioinformatics Network
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package dgbgui.modeldocument;

import java.io.Serializable;

import dgbgui.modeldocument.definition.Definition;

/**
 * @author bjnortier
 * 
 */
public class Query implements Cloneable, Serializable {
    
    
    public Query(String label, Definition definition) {
        m_label = label;
        m_definition = definition;
    }
    
    public Query(Definition definition) {
        this(definition.getTypeName() + "_" + 
                ModelDocument.getInstance().getClassCounter().getNext(definition.getClass().getName()),
             definition);
        
    }
    
    public void setLabel(String label) {
        m_label = label;
    }

    /**
     * @return The label of the query
     */
    public String getLabel() {
        return m_label;
    }

    public Definition getDefinition() {
        return m_definition;
    }

    public QueryState getState() {
        return m_state;
    }

    

    
    // -------------- Serilization -------
    
    /**
     * First serilization version
     */
    private static final long serialVersionUID = 1L;
    
    // ------------- Cloning -------------
    
    public Object clone() {
        Query o = null;
        try {
            o = (Query)super.clone();
            o.m_definition = (Definition)m_definition.clone();
        } catch (CloneNotSupportedException e) {
            System.err.println("Query can't clone");
        }

        return o;
    }
    
    // ------------- Fields ---------------
    

    // The label of the query
    private String m_label;

    // The definition node
    private Definition m_definition;

    // The state of the node
    QueryState m_state = new QueryState();

}
